package com.example.clients;

import com.example.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
public class ClientController {

    // 注入Feign客户端
    @Resource
    private BarsClient barsClient;

    @Resource
    private PostsClient postsClient;

    @GetMapping("/bars/getAllBars")
    public List<Bars> getAllBars() {
        // 调用Feign客户端的方法
        return barsClient.getAllBars();
    }

    @GetMapping("/bars/ok")
    public String ok() {
        // 调用Feign客户端的方法
        return "ok";
    }
    @RequestMapping("/bars/getUser")
    public List<Users> getUser(@RequestParam("uid") String uid){
        // 调用Mapper方法
        return barsClient.getUser(uid);
    }

    @GetMapping("/bars/StatusChange")
    public void StatusChange(@RequestParam("bid") int bid,@RequestParam("status") int status) {
        // 调用Mapper方法
        barsClient.StatusChange(bid,status);
    }

    @GetMapping("/bars/getFindBars")
    public List<Bars> getFindBars(@RequestParam("select") String select,@RequestParam("input") String input) {
        // 调用Mapper方法
        return barsClient.getFindBars(select,input);
    }


    @GetMapping("/bars/findBar")
    List<Bars> FindBar(@RequestParam("tid") Integer tid){
        return barsClient.FindBar(tid);
    }

    @GetMapping("/bars/getAllBarsByBid")
    List<Bars> getAllBarsByBid(@RequestParam("bid") Integer bid){
        return barsClient.getAllBarsByBid(bid);
    }

    @GetMapping("/bars/userFindBar")
    List<Bars> UserFindBar(@RequestParam("uid") Integer uid){
        return barsClient.userFindBar(uid);
    }

    @GetMapping("/bars/getBarsCenter")
    public List<Bars> getBarsCenter(@RequestParam("uid") Integer uid){
        return barsClient.getBarsCenter(uid);
    }

    @GetMapping("/bars/getAllApply")
    List<Bars> getAllApply(@RequestParam("bid") Integer bid){
        return barsClient.getAllApply(bid);
    }

    @GetMapping("/bars/getMyBars")
    List<Bars> getMyBars(@RequestParam("uid") Integer uid){
        return barsClient.getMyBars(uid);
    }

    @GetMapping("/bars/addBars")
    void addBars(@RequestParam("uid") Integer uid,@RequestParam("bname") String bname,@RequestParam("tid") Integer tid,@RequestParam("bimage") String bimage){
        barsClient.addBars(uid,bname,tid,bimage);
    }

    @GetMapping("/bars/delOtherid")
    void delOtherid(@RequestParam("uid") Integer uid,@RequestParam("bid") Integer bid){
        barsClient.delOtherid(uid,bid);
    }

    @GetMapping("/bars/updateBarsApply")
    void updateBarApply(@RequestParam("uid") Integer uid,@RequestParam("bid") Integer bid,@RequestParam("otherid") String otherid){
        barsClient.updateBarApply(uid,bid,otherid);
    }

    /**
     * 上面是论坛
     * 下面是帖子的部分
     */
    @GetMapping("/posts/getAll")
    public List<Posts> getAll(){
        return postsClient.getAll();
    }

    @GetMapping("/posts/addPost")
    public void addPost(@RequestParam("uid") Integer uid,@RequestParam("bid") Integer bid,@RequestParam("title") String title,
                        @RequestParam("content") String content,@RequestParam("images") String images){
        postsClient.addPost(uid,bid,title,content,images);
    }
    //帖子的评论
    @GetMapping("/posts/getDiscuss")
    public List<Discuss> getDiscuss(@RequestParam("pid") Integer pid){
        return postsClient.getDiscuss(pid);
    }


    @GetMapping("/posts/addDiscuss")
    public void addDiscuss(@RequestParam("uid") Integer uid,@RequestParam("text") String text,@RequestParam("pid") Integer pid){
        postsClient.addDiscuss(uid,text,pid);
    }

    @GetMapping("/posts/getDiscuss_Bar")
    public List<Posts> getDiscuss_Bar(@RequestParam("bid") Integer bid,@RequestParam("uid") Integer uid){
        return postsClient.getDiscuss_Bar(bid,uid);
    }

    @GetMapping("/posts/getDiscuss_User")
    public List<Posts> getDiscuss_User(@RequestParam("uid") Integer uid){
        return postsClient.getDiscuss_User(uid);
    }

    @GetMapping("/posts/findPostByPid")
    public Posts findPostByPid(@RequestParam("pid") Integer pid){
        return postsClient.findPostByPid(pid);
    }
    @GetMapping("/posts/findpbu")
    public List<Posts>  findPostByPidUid(@RequestParam("pid") Integer pid,@RequestParam("uid") Integer uid){
        return postsClient.findPostByPidUid(pid,uid);
    }
    @GetMapping("/posts/history")
    public List<Posts>  history(@RequestParam("uid") Integer uid){
        return postsClient.history(uid);
    }

    @GetMapping("/posts/moveHistory")
    public void moveHistory(@RequestParam("uid") Integer uid,@RequestParam("pid") Integer pid){
        postsClient.moveHistory(uid,pid);
    }

    @GetMapping("/posts/belike")
    public void belike(@RequestParam("uid") Integer uid,@RequestParam("sc") Integer sc,@RequestParam("pid") Integer pid){
        postsClient.belike(uid,sc,pid);
    }

    @GetMapping("/posts/getDiscuss_Pid")
    public Posts getDiscuss_Pid(@RequestParam("pid") Integer pid){
        return postsClient.getDiscuss_Pid(pid);
    }

    @GetMapping("/posts/delPosts")
    public void delPosts(@RequestParam("pid") Integer pid){
        postsClient.delPosts(pid);
    }

    @GetMapping("/posts/delDis")
    public void delDis(@RequestParam("cid") Integer cid){
        postsClient.delDis(cid);
    }

    @GetMapping("/posts/getAllDis")
    public Integer getAllDis(){
        return postsClient.getAllDis();
    }
    /**
     * email
     */
    @Resource
    private EmailClient emailClient;
    @GetMapping("/email/send")
    public void sendEmail(@RequestParam("email") String email,@RequestParam("text") String text){
        emailClient.sendEmail(email,text);
    }

    @GetMapping("/email/qrcode")
    public ResponseEntity<byte[]> generateQRCode(@RequestParam("qq") String qq) {
        byte[] qrCodeBytes = emailClient.generateQRCode(qq).getBody();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.IMAGE_PNG);
        return new ResponseEntity<>(qrCodeBytes, headers, HttpStatus.OK);
    }


    /**
     * tools
     */
    @Resource
    private AllToolsClient allToolsClient;

    @PostMapping("/tools/oss")
    public String ToolsOss(@RequestParam("file") MultipartFile file){
        return  allToolsClient.uploadFile(file);
    }

    @GetMapping("/tools/del")
    public String Del(@RequestParam("objectName") String objectName){
        return allToolsClient.Del(objectName);
    }

    @GetMapping("/tools/msg")
    public String xzs(@RequestParam("msg") String msg){
        return allToolsClient.xzs(msg);
    }

    @GetMapping("/tools/pay")  // 订单id（不能重复）和消费金额
    public void pay(@RequestParam("orderId") String orderId,@RequestParam("cost") String cost,@RequestParam("uid") Integer uid, HttpServletResponse response){
        allToolsClient.pay(orderId,cost,uid,response);
    }

    @GetMapping("/tools/getSx")
    public List<Sx> getSx(@RequestParam("title") String  title) {
        return allToolsClient.getSx(title);
    }

    @GetMapping("/tools/makeSx")
    String makeSx(@RequestParam("userid") String  userid,@RequestParam("title") String title,
                    @RequestParam("message") String message) {
        return allToolsClient.makeSx(userid,title,message);
    }

    /**
     * ms
     */
    @Resource
    private MsClient msClient;
    @GetMapping("/tasks/findProducs")
    public List<Tasks> findProducs(){
        return msClient.findProducs();
    }

    @GetMapping("/orders/addOrders")
    public void addOrders(@RequestParam("productsid") Integer productsid,@RequestParam("uid") Integer uid){
        msClient.addOrders(productsid,uid);
    }
    @GetMapping("/orders/ok")
    public String Ok(){
        return "ok";
    }
}